package com.hmbe.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Boolean success;
    private String message;
    private Object data;
    private Long total;
    private Integer code;
    private String token;

    public Result(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public Result(String message, Integer code, Object data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public Result(String message, Integer code, Object data, Long total) {
        this.message = message;
        this.code = code;
        this.data = data;
        this.total = total;
    }


    public Result(String message, Integer code, String token) {
        this.message = message;
        this.code = code;
        this.token = token;
    }

    public static Result ok(String message, StatusCode statusCode) {
        return new Result(message, statusCode.getCode());
    }

    public static Result ok(String message, StatusCode statusCode, String token) {
        return new Result(message, statusCode.getCode(), token);
    }

    public static Result ok() {
        return new Result(true, null, null, null, null, null);
    }

    public static Result ok(Object data) {
        return new Result(true, null, data, null, null, null);
    }

    public static Result ok(String message, StatusCode statusCode, Object data) {
        return new Result(message, statusCode.getCode(), data);
    }

    public static Result ok(String message, StatusCode statusCode, Object data, Long total) {
        return new Result(message, statusCode.getCode(), data, total);
    }

    public static Result ok(List<?> data, Long total) {
        return new Result(true, null, data, total, null, null);
    }

    public static Result fail(String errorMsg) {
        return new Result(false, errorMsg, null, null, StatusCode.FAILURE.getCode(), null);
    }

    public static Result fail(String errorMsg, StatusCode statusCode) {
        return new Result(errorMsg, statusCode.getCode());
    }
}
